{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting keras\n",
      "  Downloading https://files.pythonhosted.org/packages/54/e8/eaff7a09349ae9bd40d3ebaf028b49f5e2392c771f294910f75bb608b241/Keras-2.1.6-py2.py3-none-any.whl (339kB)\n",
      "\u001b[K    100% |████████████████████████████████| 348kB 2.6MB/s ta 0:00:01\n",
      "\u001b[?25hRequirement already satisfied: pyyaml in /usr/local/envs/py3env/lib/python3.5/site-packages (from keras)\n",
      "Requirement already satisfied: six>=1.9.0 in /usr/local/envs/py3env/lib/python3.5/site-packages (from keras)\n",
      "Requirement already satisfied: scipy>=0.14 in /usr/local/envs/py3env/lib/python3.5/site-packages (from keras)\n",
      "Requirement already satisfied: numpy>=1.9.1 in /usr/local/envs/py3env/lib/python3.5/site-packages (from keras)\n",
      "Requirement already satisfied: h5py in /usr/local/envs/py3env/lib/python3.5/site-packages (from keras)\n",
      "Installing collected packages: keras\n",
      "Successfully installed keras-2.1.6\n",
      "\u001b[33mYou are using pip version 9.0.3, however version 10.0.1 is available.\n",
      "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install keras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "ratings= pd.read_csv('/content/datalab/matrix_factorization_keras.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Extract the unique users\n",
    "users = ratings.User.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Extract the unique movies\n",
    "articles = ratings.Movies.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Index each user and article\n",
    "userid2idx = {o:i for i,o in enumerate(users)}\n",
    "articlesid2idx = {o:i for i,o in enumerate(articles)}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Apply the index created to the original dataset\n",
    "ratings.Movies = ratings.Movies.apply(lambda x: articlesid2idx[x])\n",
    "ratings.User = ratings.User.apply(lambda x: userid2idx[x])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Extract the number of unique users and articles\n",
    "n_users = ratings.User.nunique()\n",
    "n_articles = ratings.Movies.nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/envs/py3env/lib/python3.5/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n",
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "# Define the error metric\n",
    "import keras.backend as K\n",
    "def rmse(y_true,y_pred):\n",
    "    score = K.sqrt(K.mean(K.pow(y_true - y_pred, 2)))\n",
    "    return score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Import relevant packages\n",
    "from keras.layers import Input, Embedding, Dense, Dropout, merge, Flatten\n",
    "from keras.models import Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def embedding_input(name,n_in,n_out):\n",
    "  inp = Input(shape=(1,),dtype='int64',name=name)\n",
    "  return inp, Embedding(n_in,n_out,input_length=1)(inp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "n_factors = 2\n",
    "user_in, u = embedding_input('user_in', n_users, n_factors)\n",
    "article_in, a = embedding_input('article_in', n_articles, n_factors)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/envs/py3env/lib/python3.5/site-packages/ipykernel/__main__.py:2: UserWarning: The `merge` function is deprecated and will be removed after 08/2017. Use instead layers from `keras.layers.merge`, e.g. `add`, `concatenate`, etc.\n",
      "  from ipykernel import kernelapp as app\n",
      "/usr/local/envs/py3env/lib/python3.5/site-packages/keras/legacy/layers.py:465: UserWarning: The `Merge` layer is deprecated and will be removed after 08/2017. Use instead layers from `keras.layers.merge`, e.g. `add`, `concatenate`, etc.\n",
      "  name=name)\n"
     ]
    }
   ],
   "source": [
    "# Initialize the dot product between user matrix and movie matrix\n",
    "x = merge([u,a],mode='dot')\n",
    "x=Flatten()(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "__________________________________________________________________________________________________\n",
      "Layer (type)                    Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      "user_in (InputLayer)            (None, 1)            0                                            \n",
      "__________________________________________________________________________________________________\n",
      "article_in (InputLayer)         (None, 1)            0                                            \n",
      "__________________________________________________________________________________________________\n",
      "embedding_1 (Embedding)         (None, 1, 2)         10          user_in[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "embedding_2 (Embedding)         (None, 1, 2)         8           article_in[0][0]                 \n",
      "__________________________________________________________________________________________________\n",
      "merge_1 (Merge)                 (None, 1, 1)         0           embedding_1[0][0]                \n",
      "                                                                 embedding_2[0][0]                \n",
      "__________________________________________________________________________________________________\n",
      "flatten_1 (Flatten)             (None, 1)            0           merge_1[0][0]                    \n",
      "==================================================================================================\n",
      "Total params: 18\n",
      "Trainable params: 18\n",
      "Non-trainable params: 0\n",
      "__________________________________________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# Initialize the model specification\n",
    "from keras import optimizers\n",
    "model = Model([user_in,article_in],x)\n",
    "sgd = optimizers.SGD(lr=0.01)\n",
    "model.compile(sgd,loss='mse',metrics=[rmse])\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13/13 [==============================] - 0s 468us/step - loss: 0.0467 - rmse: 0.2161\n",
      "Epoch 721/1000\n",
      "13/13 [==============================] - 0s 283us/step - loss: 0.0463 - rmse: 0.2152\n",
      "Epoch 722/1000\n",
      "13/13 [==============================] - 0s 310us/step - loss: 0.0460 - rmse: 0.2144\n",
      "Epoch 723/1000\n",
      "13/13 [==============================] - 0s 284us/step - loss: 0.0456 - rmse: 0.2135\n",
      "Epoch 724/1000\n",
      "13/13 [==============================] - 0s 277us/step - loss: 0.0452 - rmse: 0.2127\n",
      "Epoch 725/1000\n",
      "13/13 [==============================] - 0s 277us/step - loss: 0.0449 - rmse: 0.2119\n",
      "Epoch 726/1000\n",
      "13/13 [==============================] - 0s 264us/step - loss: 0.0446 - rmse: 0.2111\n",
      "Epoch 727/1000\n",
      "13/13 [==============================] - 0s 264us/step - loss: 0.0442 - rmse: 0.2103\n",
      "Epoch 728/1000\n",
      "13/13 [==============================] - 0s 271us/step - loss: 0.0439 - rmse: 0.2095\n",
      "Epoch 729/1000\n",
      "13/13 [==============================] - 0s 317us/step - loss: 0.0435 - rmse: 0.2087\n",
      "Epoch 730/1000\n",
      "13/13 [==============================] - 0s 322us/step - loss: 0.0432 - rmse: 0.2079\n",
      "Epoch 731/1000\n",
      "13/13 [==============================] - 0s 273us/step - loss: 0.0429 - rmse: 0.2071\n",
      "Epoch 732/1000\n",
      "13/13 [==============================] - 0s 277us/step - loss: 0.0426 - rmse: 0.2063\n",
      "Epoch 733/1000\n",
      "13/13 [==============================] - 0s 287us/step - loss: 0.0423 - rmse: 0.2056\n",
      "Epoch 734/1000\n",
      "13/13 [==============================] - 0s 332us/step - loss: 0.0419 - rmse: 0.2048\n",
      "Epoch 735/1000\n",
      "13/13 [==============================] - 0s 279us/step - loss: 0.0416 - rmse: 0.2041\n",
      "Epoch 736/1000\n",
      "13/13 [==============================] - 0s 285us/step - loss: 0.0413 - rmse: 0.2033\n",
      "Epoch 737/1000\n",
      "13/13 [==============================] - 0s 295us/step - loss: 0.0410 - rmse: 0.2026\n",
      "Epoch 738/1000\n",
      "13/13 [==============================] - 0s 291us/step - loss: 0.0407 - rmse: 0.2018\n",
      "Epoch 739/1000\n",
      "13/13 [==============================] - 0s 309us/step - loss: 0.0404 - rmse: 0.2011\n",
      "Epoch 740/1000\n",
      "13/13 [==============================] - 0s 300us/step - loss: 0.0401 - rmse: 0.2004\n",
      "Epoch 741/1000\n",
      "13/13 [==============================] - 0s 303us/step - loss: 0.0399 - rmse: 0.1996\n",
      "Epoch 742/1000\n",
      "13/13 [==============================] - 0s 304us/step - loss: 0.0396 - rmse: 0.1989\n",
      "Epoch 743/1000\n",
      "13/13 [==============================] - 0s 310us/step - loss: 0.0393 - rmse: 0.1982\n",
      "Epoch 744/1000\n",
      "13/13 [==============================] - 0s 253us/step - loss: 0.0390 - rmse: 0.1975\n",
      "Epoch 745/1000\n",
      "13/13 [==============================] - 0s 226us/step - loss: 0.0387 - rmse: 0.1968\n",
      "Epoch 746/1000\n",
      "13/13 [==============================] - 0s 208us/step - loss: 0.0385 - rmse: 0.1961\n",
      "Epoch 747/1000\n",
      "13/13 [==============================] - 0s 217us/step - loss: 0.0382 - rmse: 0.1954\n",
      "Epoch 748/1000\n",
      "13/13 [==============================] - 0s 213us/step - loss: 0.0379 - rmse: 0.1948\n",
      "Epoch 749/1000\n",
      "13/13 [==============================] - 0s 223us/step - loss: 0.0377 - rmse: 0.1941\n",
      "Epoch 750/1000\n",
      "13/13 [==============================] - 0s 227us/step - loss: 0.0374 - rmse: 0.1934\n",
      "Epoch 751/1000\n",
      "13/13 [==============================] - 0s 223us/step - loss: 0.0371 - rmse: 0.1927\n",
      "Epoch 752/1000\n",
      "13/13 [==============================] - 0s 237us/step - loss: 0.0369 - rmse: 0.1921\n",
      "Epoch 753/1000\n",
      "13/13 [==============================] - 0s 215us/step - loss: 0.0366 - rmse: 0.1914\n",
      "Epoch 754/1000\n",
      "13/13 [==============================] - 0s 217us/step - loss: 0.0364 - rmse: 0.1908\n",
      "Epoch 755/1000\n",
      "13/13 [==============================] - 0s 251us/step - loss: 0.0361 - rmse: 0.1901\n",
      "Epoch 756/1000\n",
      "13/13 [==============================] - 0s 244us/step - loss: 0.0359 - rmse: 0.1895\n",
      "Epoch 757/1000\n",
      "13/13 [==============================] - 0s 220us/step - loss: 0.0357 - rmse: 0.1888\n",
      "Epoch 758/1000\n",
      "13/13 [==============================] - 0s 212us/step - loss: 0.0354 - rmse: 0.1882\n",
      "Epoch 759/1000\n",
      "13/13 [==============================] - 0s 212us/step - loss: 0.0352 - rmse: 0.1876\n",
      "Epoch 760/1000\n",
      "13/13 [==============================] - 0s 234us/step - loss: 0.0349 - rmse: 0.1869\n",
      "Epoch 761/1000\n",
      "13/13 [==============================] - 0s 234us/step - loss: 0.0347 - rmse: 0.1863\n",
      "Epoch 762/1000\n",
      "13/13 [==============================] - 0s 243us/step - loss: 0.0345 - rmse: 0.1857\n",
      "Epoch 763/1000\n",
      "13/13 [==============================] - 0s 268us/step - loss: 0.0342 - rmse: 0.1851\n",
      "Epoch 764/1000\n",
      "13/13 [==============================] - 0s 269us/step - loss: 0.0340 - rmse: 0.1845\n",
      "Epoch 765/1000\n",
      "13/13 [==============================] - 0s 286us/step - loss: 0.0338 - rmse: 0.1838\n",
      "Epoch 766/1000\n",
      "13/13 [==============================] - 0s 311us/step - loss: 0.0336 - rmse: 0.1832\n",
      "Epoch 767/1000\n",
      "13/13 [==============================] - 0s 303us/step - loss: 0.0334 - rmse: 0.1826\n",
      "Epoch 768/1000\n",
      "13/13 [==============================] - 0s 308us/step - loss: 0.0331 - rmse: 0.1821\n",
      "Epoch 769/1000\n",
      "13/13 [==============================] - 0s 323us/step - loss: 0.0329 - rmse: 0.1815\n",
      "Epoch 770/1000\n",
      "13/13 [==============================] - 0s 290us/step - loss: 0.0327 - rmse: 0.1809\n",
      "Epoch 771/1000\n",
      "13/13 [==============================] - 0s 318us/step - loss: 0.0325 - rmse: 0.1803\n",
      "Epoch 772/1000\n",
      "13/13 [==============================] - 0s 337us/step - loss: 0.0323 - rmse: 0.1797\n",
      "Epoch 773/1000\n",
      "13/13 [==============================] - 0s 486us/step - loss: 0.0321 - rmse: 0.1791\n",
      "Epoch 774/1000\n",
      "13/13 [==============================] - 0s 488us/step - loss: 0.0319 - rmse: 0.1786\n",
      "Epoch 775/1000\n",
      "13/13 [==============================] - 0s 418us/step - loss: 0.0317 - rmse: 0.1780\n",
      "Epoch 776/1000\n",
      "13/13 [==============================] - 0s 441us/step - loss: 0.0315 - rmse: 0.1774\n",
      "Epoch 777/1000\n",
      "13/13 [==============================] - 0s 500us/step - loss: 0.0313 - rmse: 0.1769\n",
      "Epoch 778/1000\n",
      "13/13 [==============================] - 0s 296us/step - loss: 0.0311 - rmse: 0.1763\n",
      "Epoch 779/1000\n",
      "13/13 [==============================] - 0s 320us/step - loss: 0.0309 - rmse: 0.1758\n",
      "Epoch 780/1000\n",
      "13/13 [==============================] - 0s 311us/step - loss: 0.0307 - rmse: 0.1752\n",
      "Epoch 781/1000\n",
      "13/13 [==============================] - 0s 332us/step - loss: 0.0305 - rmse: 0.1747\n",
      "Epoch 782/1000\n",
      "13/13 [==============================] - 0s 398us/step - loss: 0.0303 - rmse: 0.1741\n",
      "Epoch 783/1000\n",
      "13/13 [==============================] - 0s 449us/step - loss: 0.0301 - rmse: 0.1736\n",
      "Epoch 784/1000\n",
      "13/13 [==============================] - 0s 468us/step - loss: 0.0299 - rmse: 0.1730\n",
      "Epoch 785/1000\n",
      "13/13 [==============================] - 0s 283us/step - loss: 0.0298 - rmse: 0.1725\n",
      "Epoch 786/1000\n",
      "13/13 [==============================] - 0s 312us/step - loss: 0.0296 - rmse: 0.1720\n",
      "Epoch 787/1000\n",
      "13/13 [==============================] - 0s 328us/step - loss: 0.0294 - rmse: 0.1714\n",
      "Epoch 788/1000\n",
      "13/13 [==============================] - 0s 308us/step - loss: 0.0292 - rmse: 0.1709\n",
      "Epoch 789/1000\n",
      "13/13 [==============================] - 0s 294us/step - loss: 0.0290 - rmse: 0.1704\n",
      "Epoch 790/1000\n",
      "13/13 [==============================] - 0s 395us/step - loss: 0.0289 - rmse: 0.1699\n",
      "Epoch 791/1000\n",
      "13/13 [==============================] - 0s 385us/step - loss: 0.0287 - rmse: 0.1693\n",
      "Epoch 792/1000\n",
      "13/13 [==============================] - 0s 310us/step - loss: 0.0285 - rmse: 0.1688\n",
      "Epoch 793/1000\n",
      "13/13 [==============================] - 0s 327us/step - loss: 0.0283 - rmse: 0.1683\n",
      "Epoch 794/1000\n",
      "13/13 [==============================] - 0s 402us/step - loss: 0.0282 - rmse: 0.1678\n",
      "Epoch 795/1000\n",
      "13/13 [==============================] - 0s 431us/step - loss: 0.0280 - rmse: 0.1673\n",
      "Epoch 796/1000\n",
      "13/13 [==============================] - 0s 435us/step - loss: 0.0278 - rmse: 0.1668\n",
      "Epoch 797/1000\n",
      "13/13 [==============================] - 0s 442us/step - loss: 0.0277 - rmse: 0.1663\n",
      "Epoch 798/1000\n",
      "13/13 [==============================] - 0s 445us/step - loss: 0.0275 - rmse: 0.1658\n",
      "Epoch 799/1000\n",
      "13/13 [==============================] - 0s 455us/step - loss: 0.0273 - rmse: 0.1653\n",
      "Epoch 800/1000\n",
      "13/13 [==============================] - 0s 438us/step - loss: 0.0272 - rmse: 0.1648\n",
      "Epoch 801/1000\n",
      "13/13 [==============================] - 0s 430us/step - loss: 0.0270 - rmse: 0.1643\n",
      "Epoch 802/1000\n",
      "13/13 [==============================] - 0s 396us/step - loss: 0.0269 - rmse: 0.1639\n",
      "Epoch 803/1000\n",
      "13/13 [==============================] - 0s 396us/step - loss: 0.0267 - rmse: 0.1634\n",
      "Epoch 804/1000\n",
      "13/13 [==============================] - 0s 398us/step - loss: 0.0265 - rmse: 0.1629\n",
      "Epoch 805/1000\n",
      "13/13 [==============================] - 0s 468us/step - loss: 0.0264 - rmse: 0.1624\n",
      "Epoch 806/1000\n",
      "13/13 [==============================] - 0s 428us/step - loss: 0.0262 - rmse: 0.1619\n",
      "Epoch 807/1000\n",
      "13/13 [==============================] - 0s 495us/step - loss: 0.0261 - rmse: 0.1615\n",
      "Epoch 808/1000\n",
      "13/13 [==============================] - 0s 312us/step - loss: 0.0259 - rmse: 0.1610\n",
      "Epoch 809/1000\n",
      "13/13 [==============================] - 0s 323us/step - loss: 0.0258 - rmse: 0.1605\n",
      "Epoch 810/1000\n",
      "13/13 [==============================] - 0s 327us/step - loss: 0.0256 - rmse: 0.1601\n",
      "Epoch 811/1000\n",
      "13/13 [==============================] - 0s 327us/step - loss: 0.0255 - rmse: 0.1596\n",
      "Epoch 812/1000\n",
      "13/13 [==============================] - 0s 318us/step - loss: 0.0253 - rmse: 0.1592\n",
      "Epoch 813/1000\n",
      "13/13 [==============================] - 0s 399us/step - loss: 0.0252 - rmse: 0.1587\n",
      "Epoch 814/1000\n",
      "13/13 [==============================] - 0s 309us/step - loss: 0.0250 - rmse: 0.1582\n",
      "Epoch 815/1000\n",
      "13/13 [==============================] - 0s 306us/step - loss: 0.0249 - rmse: 0.1578\n",
      "Epoch 816/1000\n",
      "13/13 [==============================] - 0s 314us/step - loss: 0.0248 - rmse: 0.1573\n",
      "Epoch 817/1000\n",
      "13/13 [==============================] - 0s 426us/step - loss: 0.0246 - rmse: 0.1569\n",
      "Epoch 818/1000\n",
      "13/13 [==============================] - 0s 426us/step - loss: 0.0245 - rmse: 0.1564\n",
      "Epoch 819/1000\n",
      "13/13 [==============================] - 0s 468us/step - loss: 0.0243 - rmse: 0.1560\n",
      "Epoch 820/1000\n",
      "13/13 [==============================] - 0s 282us/step - loss: 0.0242 - rmse: 0.1556\n",
      "Epoch 821/1000\n",
      "13/13 [==============================] - 0s 282us/step - loss: 0.0241 - rmse: 0.1551\n",
      "Epoch 822/1000\n",
      "13/13 [==============================] - 0s 334us/step - loss: 0.0239 - rmse: 0.1547\n",
      "Epoch 823/1000\n",
      "13/13 [==============================] - 0s 325us/step - loss: 0.0238 - rmse: 0.1543\n",
      "Epoch 824/1000\n",
      "13/13 [==============================] - 0s 333us/step - loss: 0.0237 - rmse: 0.1538\n",
      "Epoch 825/1000\n",
      "13/13 [==============================] - 0s 321us/step - loss: 0.0235 - rmse: 0.1534\n",
      "Epoch 826/1000\n",
      "13/13 [==============================] - 0s 391us/step - loss: 0.0234 - rmse: 0.1530\n",
      "Epoch 827/1000\n",
      "13/13 [==============================] - 0s 299us/step - loss: 0.0233 - rmse: 0.1525\n",
      "Epoch 828/1000\n",
      "13/13 [==============================] - 0s 295us/step - loss: 0.0231 - rmse: 0.1521\n",
      "Epoch 829/1000\n",
      "13/13 [==============================] - 0s 305us/step - loss: 0.0230 - rmse: 0.1517\n",
      "Epoch 830/1000\n",
      "13/13 [==============================] - 0s 338us/step - loss: 0.0229 - rmse: 0.1513\n",
      "Epoch 831/1000\n",
      "13/13 [==============================] - 0s 306us/step - loss: 0.0228 - rmse: 0.1509\n",
      "Epoch 832/1000\n",
      "13/13 [==============================] - 0s 308us/step - loss: 0.0226 - rmse: 0.1504\n",
      "Epoch 833/1000\n",
      "13/13 [==============================] - 0s 337us/step - loss: 0.0225 - rmse: 0.1500\n",
      "Epoch 834/1000\n",
      "13/13 [==============================] - 0s 438us/step - loss: 0.0224 - rmse: 0.1496\n",
      "Epoch 835/1000\n",
      "13/13 [==============================] - 0s 415us/step - loss: 0.0223 - rmse: 0.1492\n",
      "Epoch 836/1000\n",
      "13/13 [==============================] - 0s 572us/step - loss: 0.0221 - rmse: 0.1488\n",
      "Epoch 837/1000\n",
      "13/13 [==============================] - 0s 297us/step - loss: 0.0220 - rmse: 0.1484\n",
      "Epoch 838/1000\n",
      "13/13 [==============================] - 0s 327us/step - loss: 0.0219 - rmse: 0.1480\n",
      "Epoch 839/1000\n",
      "13/13 [==============================] - 0s 470us/step - loss: 0.0218 - rmse: 0.1476\n",
      "Epoch 840/1000\n",
      "13/13 [==============================] - 0s 498us/step - loss: 0.0217 - rmse: 0.1472\n",
      "Epoch 841/1000\n",
      "13/13 [==============================] - 0s 394us/step - loss: 0.0216 - rmse: 0.1468\n",
      "Epoch 842/1000\n",
      "13/13 [==============================] - 0s 434us/step - loss: 0.0214 - rmse: 0.1464\n",
      "Epoch 843/1000\n",
      "13/13 [==============================] - 0s 430us/step - loss: 0.0213 - rmse: 0.1460\n",
      "Epoch 844/1000\n",
      "13/13 [==============================] - 0s 454us/step - loss: 0.0212 - rmse: 0.1456\n",
      "Epoch 845/1000\n",
      "13/13 [==============================] - 0s 439us/step - loss: 0.0211 - rmse: 0.1452\n",
      "Epoch 846/1000\n",
      "13/13 [==============================] - 0s 450us/step - loss: 0.0210 - rmse: 0.1448\n",
      "Epoch 847/1000\n",
      "13/13 [==============================] - 0s 561us/step - loss: 0.0209 - rmse: 0.1445\n",
      "Epoch 848/1000\n",
      "13/13 [==============================] - 0s 437us/step - loss: 0.0208 - rmse: 0.1441\n",
      "Epoch 849/1000\n",
      "13/13 [==============================] - 0s 424us/step - loss: 0.0206 - rmse: 0.1437\n",
      "Epoch 850/1000\n",
      "13/13 [==============================] - 0s 418us/step - loss: 0.0205 - rmse: 0.1433\n",
      "Epoch 851/1000\n",
      "13/13 [==============================] - 0s 394us/step - loss: 0.0204 - rmse: 0.1429\n",
      "Epoch 852/1000\n",
      "13/13 [==============================] - 0s 443us/step - loss: 0.0203 - rmse: 0.1426\n",
      "Epoch 853/1000\n",
      "13/13 [==============================] - 0s 433us/step - loss: 0.0202 - rmse: 0.1422\n",
      "Epoch 854/1000\n",
      "13/13 [==============================] - 0s 416us/step - loss: 0.0201 - rmse: 0.1418\n",
      "Epoch 855/1000\n",
      "13/13 [==============================] - 0s 421us/step - loss: 0.0200 - rmse: 0.1414\n",
      "Epoch 856/1000\n",
      "13/13 [==============================] - 0s 442us/step - loss: 0.0199 - rmse: 0.1411\n",
      "Epoch 857/1000\n",
      "13/13 [==============================] - 0s 435us/step - loss: 0.0198 - rmse: 0.1407\n",
      "Epoch 858/1000\n",
      "13/13 [==============================] - 0s 392us/step - loss: 0.0197 - rmse: 0.1403\n",
      "Epoch 859/1000\n",
      "13/13 [==============================] - 0s 415us/step - loss: 0.0196 - rmse: 0.1400\n",
      "Epoch 860/1000\n",
      "13/13 [==============================] - 0s 416us/step - loss: 0.0195 - rmse: 0.1396\n",
      "Epoch 861/1000\n",
      "13/13 [==============================] - 0s 418us/step - loss: 0.0194 - rmse: 0.1392\n",
      "Epoch 862/1000\n",
      "13/13 [==============================] - 0s 405us/step - loss: 0.0193 - rmse: 0.1389\n",
      "Epoch 863/1000\n",
      "13/13 [==============================] - 0s 385us/step - loss: 0.0192 - rmse: 0.1385\n",
      "Epoch 864/1000\n",
      "13/13 [==============================] - 0s 425us/step - loss: 0.0191 - rmse: 0.1382\n",
      "Epoch 865/1000\n",
      "13/13 [==============================] - 0s 433us/step - loss: 0.0190 - rmse: 0.1378\n",
      "Epoch 866/1000\n",
      "13/13 [==============================] - 0s 415us/step - loss: 0.0189 - rmse: 0.1375\n",
      "Epoch 867/1000\n",
      "13/13 [==============================] - 0s 437us/step - loss: 0.0188 - rmse: 0.1371\n",
      "Epoch 868/1000\n",
      "13/13 [==============================] - 0s 439us/step - loss: 0.0187 - rmse: 0.1367\n",
      "Epoch 869/1000\n",
      "13/13 [==============================] - 0s 437us/step - loss: 0.0186 - rmse: 0.1364\n",
      "Epoch 870/1000\n",
      "13/13 [==============================] - 0s 411us/step - loss: 0.0185 - rmse: 0.1361\n",
      "Epoch 871/1000\n",
      "13/13 [==============================] - 0s 420us/step - loss: 0.0184 - rmse: 0.1357\n",
      "Epoch 872/1000\n",
      "13/13 [==============================] - 0s 414us/step - loss: 0.0183 - rmse: 0.1354\n",
      "Epoch 873/1000\n",
      "13/13 [==============================] - 0s 441us/step - loss: 0.0182 - rmse: 0.1350\n",
      "Epoch 874/1000\n",
      "13/13 [==============================] - 0s 416us/step - loss: 0.0181 - rmse: 0.1347\n",
      "Epoch 875/1000\n",
      "13/13 [==============================] - 0s 423us/step - loss: 0.0180 - rmse: 0.1343\n",
      "Epoch 876/1000\n",
      "13/13 [==============================] - 0s 434us/step - loss: 0.0180 - rmse: 0.1340\n",
      "Epoch 877/1000\n",
      "13/13 [==============================] - 0s 459us/step - loss: 0.0179 - rmse: 0.1337\n",
      "Epoch 878/1000\n",
      "13/13 [==============================] - 0s 543us/step - loss: 0.0178 - rmse: 0.1333\n",
      "Epoch 879/1000\n",
      "13/13 [==============================] - 0s 310us/step - loss: 0.0177 - rmse: 0.1330\n",
      "Epoch 880/1000\n",
      "13/13 [==============================] - 0s 315us/step - loss: 0.0176 - rmse: 0.1327\n",
      "Epoch 881/1000\n",
      "13/13 [==============================] - 0s 410us/step - loss: 0.0175 - rmse: 0.1323\n",
      "Epoch 882/1000\n",
      "13/13 [==============================] - 0s 432us/step - loss: 0.0174 - rmse: 0.1320\n",
      "Epoch 883/1000\n",
      "13/13 [==============================] - 0s 403us/step - loss: 0.0173 - rmse: 0.1317\n",
      "Epoch 884/1000\n",
      "13/13 [==============================] - 0s 426us/step - loss: 0.0172 - rmse: 0.1313\n",
      "Epoch 885/1000\n",
      "13/13 [==============================] - 0s 440us/step - loss: 0.0172 - rmse: 0.1310\n",
      "Epoch 886/1000\n",
      "13/13 [==============================] - 0s 443us/step - loss: 0.0171 - rmse: 0.1307\n",
      "Epoch 887/1000\n",
      "13/13 [==============================] - 0s 451us/step - loss: 0.0170 - rmse: 0.1304\n",
      "Epoch 888/1000\n",
      "13/13 [==============================] - 0s 425us/step - loss: 0.0169 - rmse: 0.1300\n",
      "Epoch 889/1000\n",
      "13/13 [==============================] - 0s 394us/step - loss: 0.0168 - rmse: 0.1297\n",
      "Epoch 890/1000\n",
      "13/13 [==============================] - 0s 448us/step - loss: 0.0167 - rmse: 0.1294\n",
      "Epoch 891/1000\n",
      "13/13 [==============================] - 0s 442us/step - loss: 0.0167 - rmse: 0.1291\n",
      "Epoch 892/1000\n",
      "13/13 [==============================] - 0s 454us/step - loss: 0.0166 - rmse: 0.1288\n",
      "Epoch 893/1000\n",
      "13/13 [==============================] - 0s 319us/step - loss: 0.0165 - rmse: 0.1285\n",
      "Epoch 894/1000\n",
      "13/13 [==============================] - 0s 310us/step - loss: 0.0164 - rmse: 0.1281\n",
      "Epoch 895/1000\n",
      "13/13 [==============================] - 0s 310us/step - loss: 0.0163 - rmse: 0.1278\n",
      "Epoch 896/1000\n",
      "13/13 [==============================] - 0s 309us/step - loss: 0.0163 - rmse: 0.1275\n",
      "Epoch 897/1000\n",
      "13/13 [==============================] - 0s 313us/step - loss: 0.0162 - rmse: 0.1272\n",
      "Epoch 898/1000\n",
      "13/13 [==============================] - 0s 313us/step - loss: 0.0161 - rmse: 0.1269\n",
      "Epoch 899/1000\n",
      "13/13 [==============================] - 0s 388us/step - loss: 0.0160 - rmse: 0.1266\n",
      "Epoch 900/1000\n",
      "13/13 [==============================] - 0s 389us/step - loss: 0.0159 - rmse: 0.1263\n",
      "Epoch 901/1000\n",
      "13/13 [==============================] - 0s 425us/step - loss: 0.0159 - rmse: 0.1260\n",
      "Epoch 902/1000\n",
      "13/13 [==============================] - 0s 292us/step - loss: 0.0158 - rmse: 0.1257\n",
      "Epoch 903/1000\n",
      "13/13 [==============================] - 0s 315us/step - loss: 0.0157 - rmse: 0.1254\n",
      "Epoch 904/1000\n",
      "13/13 [==============================] - 0s 386us/step - loss: 0.0156 - rmse: 0.1251\n",
      "Epoch 905/1000\n",
      "13/13 [==============================] - 0s 406us/step - loss: 0.0156 - rmse: 0.1248\n",
      "Epoch 906/1000\n",
      "13/13 [==============================] - 0s 651us/step - loss: 0.0155 - rmse: 0.1245\n",
      "Epoch 907/1000\n",
      "13/13 [==============================] - 0s 306us/step - loss: 0.0154 - rmse: 0.1242\n",
      "Epoch 908/1000\n",
      "13/13 [==============================] - 0s 384us/step - loss: 0.0153 - rmse: 0.1239\n",
      "Epoch 909/1000\n",
      "13/13 [==============================] - 0s 432us/step - loss: 0.0153 - rmse: 0.1236\n",
      "Epoch 910/1000\n",
      "13/13 [==============================] - 0s 371us/step - loss: 0.0152 - rmse: 0.1233\n",
      "Epoch 911/1000\n",
      "13/13 [==============================] - 0s 415us/step - loss: 0.0151 - rmse: 0.1230\n",
      "Epoch 912/1000\n",
      "13/13 [==============================] - 0s 465us/step - loss: 0.0151 - rmse: 0.1227\n",
      "Epoch 913/1000\n",
      "13/13 [==============================] - 0s 466us/step - loss: 0.0150 - rmse: 0.1224\n",
      "Epoch 914/1000\n",
      "13/13 [==============================] - 0s 425us/step - loss: 0.0149 - rmse: 0.1221\n",
      "Epoch 915/1000\n",
      "13/13 [==============================] - 0s 381us/step - loss: 0.0148 - rmse: 0.1218\n",
      "Epoch 916/1000\n",
      "13/13 [==============================] - 0s 425us/step - loss: 0.0148 - rmse: 0.1215\n",
      "Epoch 917/1000\n",
      "13/13 [==============================] - 0s 446us/step - loss: 0.0147 - rmse: 0.1212\n",
      "Epoch 918/1000\n",
      "13/13 [==============================] - 0s 420us/step - loss: 0.0146 - rmse: 0.1210\n",
      "Epoch 919/1000\n",
      "13/13 [==============================] - 0s 418us/step - loss: 0.0146 - rmse: 0.1207\n",
      "Epoch 920/1000\n",
      "13/13 [==============================] - 0s 430us/step - loss: 0.0145 - rmse: 0.1204\n",
      "Epoch 921/1000\n",
      "13/13 [==============================] - 0s 394us/step - loss: 0.0144 - rmse: 0.1201\n",
      "Epoch 922/1000\n",
      "13/13 [==============================] - 0s 426us/step - loss: 0.0144 - rmse: 0.1198\n",
      "Epoch 923/1000\n",
      "13/13 [==============================] - 0s 446us/step - loss: 0.0143 - rmse: 0.1196\n",
      "Epoch 924/1000\n",
      "13/13 [==============================] - 0s 454us/step - loss: 0.0142 - rmse: 0.1193\n",
      "Epoch 925/1000\n",
      "13/13 [==============================] - 0s 446us/step - loss: 0.0142 - rmse: 0.1190\n",
      "Epoch 926/1000\n",
      "13/13 [==============================] - 0s 443us/step - loss: 0.0141 - rmse: 0.1187\n",
      "Epoch 927/1000\n",
      "13/13 [==============================] - 0s 453us/step - loss: 0.0140 - rmse: 0.1184\n",
      "Epoch 928/1000\n",
      "13/13 [==============================] - 0s 434us/step - loss: 0.0140 - rmse: 0.1182\n",
      "Epoch 929/1000\n",
      "13/13 [==============================] - 0s 517us/step - loss: 0.0139 - rmse: 0.1179\n",
      "Epoch 930/1000\n",
      "13/13 [==============================] - 0s 312us/step - loss: 0.0138 - rmse: 0.1176\n",
      "Epoch 931/1000\n",
      "13/13 [==============================] - 0s 384us/step - loss: 0.0138 - rmse: 0.1173\n",
      "Epoch 932/1000\n",
      "13/13 [==============================] - 0s 733us/step - loss: 0.0137 - rmse: 0.1171\n",
      "Epoch 933/1000\n",
      "13/13 [==============================] - 0s 423us/step - loss: 0.0136 - rmse: 0.1168\n",
      "Epoch 934/1000\n",
      "13/13 [==============================] - 0s 379us/step - loss: 0.0136 - rmse: 0.1165\n",
      "Epoch 935/1000\n",
      "13/13 [==============================] - 0s 398us/step - loss: 0.0135 - rmse: 0.1163\n",
      "Epoch 936/1000\n",
      "13/13 [==============================] - 0s 620us/step - loss: 0.0135 - rmse: 0.1160\n",
      "Epoch 937/1000\n",
      "13/13 [==============================] - 0s 281us/step - loss: 0.0134 - rmse: 0.1157\n",
      "Epoch 938/1000\n",
      "13/13 [==============================] - 0s 308us/step - loss: 0.0133 - rmse: 0.1155\n",
      "Epoch 939/1000\n",
      "13/13 [==============================] - 0s 301us/step - loss: 0.0133 - rmse: 0.1152\n",
      "Epoch 940/1000\n",
      "13/13 [==============================] - 0s 311us/step - loss: 0.0132 - rmse: 0.1149\n",
      "Epoch 941/1000\n",
      "13/13 [==============================] - 0s 239us/step - loss: 0.0132 - rmse: 0.1147\n",
      "Epoch 942/1000\n",
      "13/13 [==============================] - 0s 215us/step - loss: 0.0131 - rmse: 0.1144\n",
      "Epoch 943/1000\n",
      "13/13 [==============================] - 0s 223us/step - loss: 0.0130 - rmse: 0.1142\n",
      "Epoch 944/1000\n",
      "13/13 [==============================] - 0s 242us/step - loss: 0.0130 - rmse: 0.1139\n",
      "Epoch 945/1000\n",
      "13/13 [==============================] - 0s 235us/step - loss: 0.0129 - rmse: 0.1137\n",
      "Epoch 946/1000\n",
      "13/13 [==============================] - 0s 259us/step - loss: 0.0129 - rmse: 0.1134\n",
      "Epoch 947/1000\n",
      "13/13 [==============================] - 0s 296us/step - loss: 0.0128 - rmse: 0.1131\n",
      "Epoch 948/1000\n",
      "13/13 [==============================] - 0s 269us/step - loss: 0.0127 - rmse: 0.1129\n",
      "Epoch 949/1000\n",
      "13/13 [==============================] - 0s 303us/step - loss: 0.0127 - rmse: 0.1126\n",
      "Epoch 950/1000\n",
      "13/13 [==============================] - 0s 294us/step - loss: 0.0126 - rmse: 0.1124\n",
      "Epoch 951/1000\n",
      "13/13 [==============================] - 0s 357us/step - loss: 0.0126 - rmse: 0.1121\n",
      "Epoch 952/1000\n",
      "13/13 [==============================] - 0s 318us/step - loss: 0.0125 - rmse: 0.1119\n",
      "Epoch 953/1000\n",
      "13/13 [==============================] - 0s 320us/step - loss: 0.0125 - rmse: 0.1116\n",
      "Epoch 954/1000\n",
      "13/13 [==============================] - 0s 320us/step - loss: 0.0124 - rmse: 0.1114\n",
      "Epoch 955/1000\n",
      "13/13 [==============================] - 0s 310us/step - loss: 0.0123 - rmse: 0.1111\n",
      "Epoch 956/1000\n",
      "13/13 [==============================] - 0s 309us/step - loss: 0.0123 - rmse: 0.1109\n",
      "Epoch 957/1000\n",
      "13/13 [==============================] - 0s 434us/step - loss: 0.0122 - rmse: 0.1106\n",
      "Epoch 958/1000\n",
      "13/13 [==============================] - 0s 445us/step - loss: 0.0122 - rmse: 0.1104\n",
      "Epoch 959/1000\n",
      "13/13 [==============================] - 0s 471us/step - loss: 0.0121 - rmse: 0.1101\n",
      "Epoch 960/1000\n",
      "13/13 [==============================] - 0s 311us/step - loss: 0.0121 - rmse: 0.1099\n",
      "Epoch 961/1000\n",
      "13/13 [==============================] - 0s 295us/step - loss: 0.0120 - rmse: 0.1096\n",
      "Epoch 962/1000\n",
      "13/13 [==============================] - 0s 305us/step - loss: 0.0120 - rmse: 0.1094\n",
      "Epoch 963/1000\n",
      "13/13 [==============================] - 0s 307us/step - loss: 0.0119 - rmse: 0.1092\n",
      "Epoch 964/1000\n",
      "13/13 [==============================] - 0s 397us/step - loss: 0.0119 - rmse: 0.1089\n",
      "Epoch 965/1000\n",
      "13/13 [==============================] - 0s 390us/step - loss: 0.0118 - rmse: 0.1087\n",
      "Epoch 966/1000\n",
      "13/13 [==============================] - 0s 426us/step - loss: 0.0118 - rmse: 0.1084\n",
      "Epoch 967/1000\n",
      "13/13 [==============================] - 0s 418us/step - loss: 0.0117 - rmse: 0.1082\n",
      "Epoch 968/1000\n",
      "13/13 [==============================] - 0s 451us/step - loss: 0.0117 - rmse: 0.1080\n",
      "Epoch 969/1000\n",
      "13/13 [==============================] - 0s 437us/step - loss: 0.0116 - rmse: 0.1077\n",
      "Epoch 970/1000\n",
      "13/13 [==============================] - 0s 451us/step - loss: 0.0116 - rmse: 0.1075\n",
      "Epoch 971/1000\n",
      "13/13 [==============================] - 0s 447us/step - loss: 0.0115 - rmse: 0.1073\n",
      "Epoch 972/1000\n",
      "13/13 [==============================] - 0s 428us/step - loss: 0.0115 - rmse: 0.1070\n",
      "Epoch 973/1000\n",
      "13/13 [==============================] - 0s 421us/step - loss: 0.0114 - rmse: 0.1068\n",
      "Epoch 974/1000\n",
      "13/13 [==============================] - 0s 438us/step - loss: 0.0114 - rmse: 0.1066\n",
      "Epoch 975/1000\n",
      "13/13 [==============================] - 0s 479us/step - loss: 0.0113 - rmse: 0.1063\n",
      "Epoch 976/1000\n",
      "13/13 [==============================] - 0s 325us/step - loss: 0.0113 - rmse: 0.1061\n",
      "Epoch 977/1000\n",
      "13/13 [==============================] - 0s 311us/step - loss: 0.0112 - rmse: 0.1059\n",
      "Epoch 978/1000\n",
      "13/13 [==============================] - 0s 316us/step - loss: 0.0112 - rmse: 0.1056\n",
      "Epoch 979/1000\n",
      "13/13 [==============================] - 0s 317us/step - loss: 0.0111 - rmse: 0.1054\n",
      "Epoch 980/1000\n",
      "13/13 [==============================] - 0s 385us/step - loss: 0.0111 - rmse: 0.1052\n",
      "Epoch 981/1000\n",
      "13/13 [==============================] - 0s 328us/step - loss: 0.0110 - rmse: 0.1049\n",
      "Epoch 982/1000\n",
      "13/13 [==============================] - 0s 411us/step - loss: 0.0110 - rmse: 0.1047\n",
      "Epoch 983/1000\n",
      "13/13 [==============================] - 0s 423us/step - loss: 0.0109 - rmse: 0.1045\n",
      "Epoch 984/1000\n",
      "13/13 [==============================] - 0s 536us/step - loss: 0.0109 - rmse: 0.1043\n",
      "Epoch 985/1000\n",
      "13/13 [==============================] - 0s 462us/step - loss: 0.0108 - rmse: 0.1040\n",
      "Epoch 986/1000\n",
      "13/13 [==============================] - 0s 425us/step - loss: 0.0108 - rmse: 0.1038\n",
      "Epoch 987/1000\n",
      "13/13 [==============================] - 0s 911us/step - loss: 0.0107 - rmse: 0.1036\n",
      "Epoch 988/1000\n",
      "13/13 [==============================] - 0s 434us/step - loss: 0.0107 - rmse: 0.1034\n",
      "Epoch 989/1000\n",
      "13/13 [==============================] - 0s 434us/step - loss: 0.0106 - rmse: 0.1032\n",
      "Epoch 990/1000\n",
      "13/13 [==============================] - 0s 419us/step - loss: 0.0106 - rmse: 0.1029\n",
      "Epoch 991/1000\n",
      "13/13 [==============================] - 0s 427us/step - loss: 0.0106 - rmse: 0.1027\n",
      "Epoch 992/1000\n",
      "13/13 [==============================] - 0s 435us/step - loss: 0.0105 - rmse: 0.1025\n",
      "Epoch 993/1000\n",
      "13/13 [==============================] - 0s 430us/step - loss: 0.0105 - rmse: 0.1023\n",
      "Epoch 994/1000\n",
      "13/13 [==============================] - 0s 432us/step - loss: 0.0104 - rmse: 0.1021\n",
      "Epoch 995/1000\n",
      "13/13 [==============================] - 0s 419us/step - loss: 0.0104 - rmse: 0.1018\n",
      "Epoch 996/1000\n",
      "13/13 [==============================] - 0s 414us/step - loss: 0.0103 - rmse: 0.1016\n",
      "Epoch 997/1000\n",
      "13/13 [==============================] - 0s 386us/step - loss: 0.0103 - rmse: 0.1014\n",
      "Epoch 998/1000\n",
      "13/13 [==============================] - 0s 430us/step - loss: 0.0102 - rmse: 0.1012\n",
      "Epoch 999/1000\n",
      "13/13 [==============================] - 0s 449us/step - loss: 0.0102 - rmse: 0.1010\n",
      "Epoch 1000/1000\n",
      "13/13 [==============================] - 0s 407us/step - loss: 0.0102 - rmse: 0.1008\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x7fdb81636e80>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Fit the model by specifying inputs and output\n",
    "model.fit([ratings.User,ratings.Movies], ratings.Actual, nb_epoch=1000, batch_size=13)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.3606772,  1.6446526],\n",
       "       [ 1.0029647,  1.3566955],\n",
       "       [-1.4094337,  1.6923367],\n",
       "       [-1.0425398,  1.4308459],\n",
       "       [-1.2908196,  1.4010738]], dtype=float32)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# User matrix\n",
    "model.get_weights()[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.3724959,  1.7509296],\n",
       "       [ 1.5061257,  1.8171026],\n",
       "       [ 0.6696424,  1.235024 ],\n",
       "       [-1.7306372,  1.8775703]], dtype=float32)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Movie matrix\n",
    "model.get_weights()[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
